#include "player.h"

Player::Player()
{
    mMoveSpeed = 4;
    gravity = 0.5;
    vy=0;
    isJumping = false;
}

void Player::boundaryJudge()
{
    if(this->x()<20)
    {
        this->setX(20);
    }
    if(this->x()>GameDefine::ScreenWidth-this->boundingRect().width())

    {
        this->setX(GameDefine::ScreenWidth-this->boundingRect().width());
    }
    if(this->y()>GameDefine::ScreenHeight-this->boundingRect().height()-30)

    {
        this->setY(GameDefine::ScreenHeight-this->boundingRect().height()-30);

    }
    //单独检测左右两个凸出部分
    if(this->x()>1131 && this->y()>860)//1200,860
    {
        this->setX(1130);
    }
    if(this->x()<174 && this->y() > 299 && this->y() <301)//40,250
    {
        this->setPos(175,300);
    }
}

void Player::down()
{
    vy += gravity;
    this->setY(this->y()+vy);
}

void Player::jump()
{
    if(!isJumping)
    {
        vy = 12;
        isJumping = true;
    }
}

void Player::watergreenJudge(int _x,int _y)
{

        if(this->x()>=800 && this->x()<=900 && this->y()>=680 && this->y()<=698)//绿水(840,715,140,73
        {
            this->setPos(_x,_y);
        }
}

Player::~Player()
{

}

